﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;

namespace Bacon_FTP_Client
{
    /// <summary>
    /// Class that models a client for the server.
    /// </summary>
    public class Client
    {
        #region Properties()
        internal Guid _clientID { get; private set; }
        internal string _hostname { get; set; }
        internal string _username { get; set; }
        internal string _password { get; set; }
        internal int _port { get; set; }
        internal bool _conected { get; private set; }
        internal NetworkStream _netStream { get; private set; }
        internal TcpClient _tcpClient { get; private set; }
        #endregion

        #region Constructors()
        /// <summary>
        /// Empty constructor, only sets GUID and conected properties.
        /// </summary>
        public Client()
        {
            _clientID = Guid.NewGuid();
            _conected = false;
        }

        /// <summary>
        /// Full constructor of a client.
        /// </summary>
        /// <param name="hostname">Hostname IP of the server</param>
        /// <param name="username">Username for the server</param>
        /// <param name="password">Password of the user</param>
        /// <param name="port">port number for the connection</param>
        public Client(string hostname, string username, string password, int port)
        {
            _clientID = Guid.NewGuid();
            _hostname = hostname;
            _username = username;
            _password = password;
            _port = port;
        }
        #endregion

        #region Implementation()
        /// <summary>
        /// Sets the connected status of the client.
        /// </summary>
        /// <param name="conectedstatus">Status of the connection</param>
        public void SetConnectedStatus(bool conectedstatus)
        {
            _conected = conectedstatus;
        }

        /// <summary>
        /// Sets the TcpClient for the client.
        /// </summary>
        /// <param name="tcpClient"></param>
        public void SetNetworkParameters(TcpClient tcpClient)
        {
            _tcpClient = tcpClient;
        }

        /// <summary>
        /// Retrieves the NetworkStream to establish the connection.
        /// </summary>
        /// <param name="endPoint">IPEndPoint for the server.</param>
        /// <param name="tcpClient">TcpClient instance.</param>
        public void GetNetworkStream(IPEndPoint endPoint, TcpClient tcpClient)
        {
            _tcpClient.Connect(endPoint);
            _netStream = tcpClient.GetStream();
        }
        #endregion
    }
}
